<template>
    <div>
        <h1>医生信息列表</h1>
        <div>
            医生姓名 : <input type="text" v-model="qureyInfo.doctorName">
            职称 : <select v-model="qureyInfo.jobName">
                <option value="">请选择</option>
                <option value="院长">院长</option>
                <option value="主任医师">主任医师</option>
                <option value="医师">医师</option>
                <option value="护士长">护士长</option>
                <option value="护士">护士</option>
            </select>
            <input type="button" value="查询" @click="show()">
        </div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>医生id</td>
                    <td>医生名称</td>
                    <td>医生照片</td>
                    <td>科室名称</td>
                    <td>职称</td>
                    <td>学历</td>
                    <td>是否开通账号</td>
                    <td>类型</td>
                    <td>创建时间</td>
                    <td>更新时间</td>
                    <td>操作</td>
                </tr>
                <tr v-for="item in data.info">
                    <td>{{ item.doctorId }}</td>
                    <td>{{ item.doctorName }}</td>
                    <td><img :src="item.photo" alt="" width="100" height="100"></td>
                    <td>{{ item.departmentName }}</td>
                    <td>{{ item.title }}</td>
                    <td>{{ item.eeuBgr }}</td>
                    <td>{{ item.hospital }}</td>
                    <td>{{ item.state ? "开通" : "未开通" }}</td>
                    <td>{{ item.types }}</td>
                    <td>{{ moment(item.createTime).format("YYYY-MM-DD") }}</td>
                    <td>{{ moment(item.updateTime).format("YYYY-MM-DD") }}</td>
                    <td>
                        <input type="button" value="删除" @click="del(item.doctorId)">
                        <input type="button" value="查看医生简介" @click="getDoctorItem(item.doctorId)">
                    </td>
                </tr>
            </tbody>
        </table>
        <div>
            <span>共{{ data.totalcount }}条</span>
            <span>第{{ qureyInfo.pageindex }}页/共{{ data.totalpage }}条</span>
            <input type="button" value="首页" @click="goPage(1)">
            <input type="button" value="上一页" @click="goPage(qureyInfo.pageindex - 1)">
            <span v-for="item in data.totalpage"> {{ item }}</span>
            <input type="button" value="下一页" @click="goPage(qureyInfo.pageindex + 1)">
            <input type="button" value="尾页" @click="goPage(data.totalpage)">
        </div>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import moment from 'moment';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();

onMounted(() => {
    getdata();
})

let qureyInfo: any = reactive({
    doctorName: "",
    jobName: "",
    pageindex: 1,
    pagesize: 3
})
let data: any = reactive({
    totalcount: 0,
    totalpage: 0,
    info: []
})
const getdata = () => {
    axios({
        url: '/api/Ward/GetDoctorinformationList',
        method: 'get',
        params: qureyInfo,
    })
        .then(res => {
            Object.assign(data, res.data);
        })
        .catch(err => {

        })
}
const goPage = (num: any) => {
    if (num < 1) {
        qureyInfo.pageindex = num;
        return;
    }
    if (num > data.totalpage) {
        qureyInfo.pageindex = data.totalpage;
        return;
    }
    qureyInfo.pageindex = num;
    getdata();
}

const show = () => {
    qureyInfo.pageindex = 1;
    getdata();
}

const del = (id: any) => {
    if (confirm("你确定要删除吗")) {
        axios({
            url: '/api/Ward/DoctorDelete',
            method: 'delete',
            params: { id: id }
        })
            .then(res => {
                if (res.data > 0) {
                    alert("删除成功");
                    getdata();
                    return;
                }
                else {
                    alert("删除失败");
                    return;
                }
            })
            .catch(err => {

            })
    }

}
const getDoctorItem = (id: any) => {
    router.push({
        path: '/doctorItem',
        query: {
            id: id
        }
    })
}
</script>

<style scoped></style>